package com.youbenzi.dockerpool;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DockerCreater implements Runnable{

	private static final ExecutorService executorService = Executors.newFixedThreadPool(2);
	
	private String type;
	private String host;
	private DockerFactory dockerFactory;
	
	public DockerCreater(String type, String host, DockerFactory dockerFactory) {
		super();
		this.type = type;
		this.host = host;
		this.dockerFactory = dockerFactory;
	}

	@Override
	public void run() {
		int port = Register.unregisteredPort(type, host);
		try {
			dockerFactory.runContainer(type, host, port);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void create() {
		executorService.execute(this);
	}
}
